package ltd.ueic.allypay.alipay.config;

import com.alipay.api.DefaultAlipayClient;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * 支付宝支付相关配置
 *
 * @author Kevin Yang
 * @version 1.0.0
 * Created by Kevin Yang on 2018/11/30 13:58.
 */
@Slf4j
@Getter
@Setter
@Configuration
@ConfigurationProperties("libra.allypay.alipay.config")
public class AlipayConfig {

    /**
     * 商户-appId
     */
    private String appId = "";
    /**
     * 私钥(pkcs8格式的)
     */
    private String merchantPrivateKey = "";
    /**
     * 服务器异步通知页面路径
     * 需http://或者https://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
     */
    private String notifyUrl = "http://商户网关地址/alipay.trade.wap.pay-JAVA-UTF-8/notify_url.jsp";
    /**
     * 页面跳转同步通知页面路径
     * 需http://或者https://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问 商户可以自定义同步跳转地址
     */
    private String returnUrl = "http://商户网关地址/alipay.trade.wap.pay-JAVA-UTF-8/return_url.jsp";
    /**
     * 请求网关地址
     */
    private String gatewayUrl = "https://openapi.alipay.com/gateway.do";
    /**
     * 编码
     */
    private String charset = "UTF-8";
    /**
     * 返回格式
     */
    private String format = "json";
    /**
     * 支付宝公钥
     */
    private String alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu6FAv6JRC9OjTYXHB7Ynn2b2yKGxV0Gcll7F1nZHz8sMapMlB9DtebKhpbR7UlddiPC0X644fzq2r/s3DOZfnAYK1KkbNLXNRDnYpzQwijW12D+KBXlB7IN4A4AToGb8nba8foBed4moSeLA36JHuHyM2Q1MKQbE1JZb2rvRhL8cOueyVZ2r4672wmM80/Xv/9pbpV3v5rbnuTZ0HBqrgdrU765cFfkctS4haoW1c93JbWHV8v46m8dIge4iHDWMH1rtUw4ZuBipEi6bpU/36oW+C3fX8YhfEjcnZ0svXCSb3LXBG7K1Wmd1ne4f+FFLaFLbPIJ8PzuHFGvGZ4VRjQIDAQAB";
    /**
     * 日志记录目录
     */
    private String logPath = "/log";
    /**
     * RSA2
     */
    private String signType = "RSA2";

    /**
     * 生成支付请求客户端
     *
     * @return
     */
    public DefaultAlipayClient getAliPayClient() {
        return new DefaultAlipayClient(
                this.gatewayUrl,
                this.appId,
                this.merchantPrivateKey,
                this.format,
                this.charset,
                this.alipayPublicKey,
                this.signType);
    }
}
